package com.gitee.hljdrl.dsbridge.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.ffsky.logger.L;
import com.gitee.hljdrl.dsbridge.R;
import com.gitee.hljdrl.dsbridge.basis.ViewPresenter;
import com.gitee.hljdrl.dsbridge.clean.DSViewPresenter;

public class WebFragment extends Fragment {

    protected String TAG = "WebFragment";
    protected ViewPresenter mViewPresenter;

    protected @LayoutRes int mLayoutId = R.layout.dsb_web_fragment;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        L.i(TAG,"onCreate");
    }

    public void setLayoutId(@LayoutRes int layoutId) {
        this.mLayoutId = layoutId;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        L.i(TAG,"onCreateView");
        View view = inflater.inflate(mLayoutId, container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        L.i(TAG,"onViewCreated");
        super.onViewCreated(view, savedInstanceState);
        initView();
        initEvent();
    }

    protected ViewPresenter createViewPresenter() {
        return new DSViewPresenter();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        L.i(TAG,"onDestroyView");
    }

    @Override
    public void onResume() {
        super.onResume();
        L.i(TAG,"onResume");
        if (mViewPresenter != null) {
            mViewPresenter.onResume();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        L.i(TAG,"onPause");
        if (mViewPresenter != null) {
            mViewPresenter.onPause();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        L.i(TAG,"onDestroy");
        if (mViewPresenter != null) {
            mViewPresenter.onDestroy();
        }
    }

    protected void initView() {
        L.i(TAG,"initView");
        mViewPresenter = createViewPresenter();
        if (mViewPresenter != null) {
            mViewPresenter.onCreate(getActivity(), getView(),getArguments());
        }
    }

    protected void initEvent() {
        L.i(TAG,"initEvent");
    }
}
